# Maintainer: Jeroen Ooms <jeroen@berkeley.edu>

_realname=rrdtool
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=1.8.0
pkgrel=3
pkgdesc="Round Robin Database (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32' 'clangarm64')
url='https://oss.oetiker.ch/rrdtool/'
license=('GPL2')
makedepends=("${MINGW_PACKAGE_PREFIX}-autotools"
             "${MINGW_PACKAGE_PREFIX}-cc")
depends=("${MINGW_PACKAGE_PREFIX}-glib2"
         "${MINGW_PACKAGE_PREFIX}-pango"
         "${MINGW_PACKAGE_PREFIX}-libxml2")
source=("https://github.com/oetiker/rrdtool-1.x/releases/download/v${pkgver}/${_realname}-${pkgver}.tar.gz"
        "001-rrdtool-1.8.0-BUILD_DATE.patch"
        "002-rrdtool-1.8.0-rrd_first.patch")
sha256sums=('bd37614137d7a8dc523359648eb2a81631a34fd91a82ed5581916a52c08433f4'
            '000269cb37db0be8c01b14931c5594238408537ea208d2304bd58c3494fa7bad'
            '0fd1199d8415d700c962707b82ff3065fa05b21bca5e8f7e83bdcc98acfbcde1')

prepare() {
  cp -Rf "${srcdir}/${_realname}-${pkgver}" "${srcdir}"/build-${CARCH}
  cd "${srcdir}"/build-${CARCH}
  # https://github.com/oetiker/rrdtool-1.x/commit/e59f703
  patch -p1 -i ${srcdir}/001-rrdtool-1.8.0-BUILD_DATE.patch
  # https://github.com/oetiker/rrdtool-1.x/commit/b74a0d6
  patch -p1 -i ${srcdir}/002-rrdtool-1.8.0-rrd_first.patch
  ./bootstrap
}

build() {
  cd "${srcdir}"/build-${CARCH}

  # Do not add --host and --target options, otherwise
  # executables are installed with target triplet prefixes
  ./configure \
    --prefix=${MINGW_PREFIX} \
    --build=${MINGW_CHOST} \
    --enable-static \
    --disable-shared \
    --disable-tcl \
    --disable-python \
    --disable-docs \
    --disable-nls \
    --disable-perl \
    --disable-mmap \
    --disable-ruby \
    --disable-rrdcached

  make
}

package() {
  cd "${srcdir}"/build-${CARCH}
  make install DESTDIR="${pkgdir}"

  install -Dm644 "${srcdir}/${_realname}-${pkgver}/COPYRIGHT" "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/COPYRIGHT"
  install -Dm644 "${srcdir}/${_realname}-${pkgver}/LICENSE" "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE"
}
